#include "AppHelper.h"
#include "cfg.h"
#include "host.h"

void MakeListString( Cfg* cfg, HostSub* hostSub, THosts* hosts, char* buf )
{
	Host* host = hosts->GetHostByAddr( hostSub );
	if( host && IsSameHost( hostSub, &host->hostSub ) )
		MakeListString( cfg, host, buf );
	else
	{
		Host host;
		memset( &host, 0, sizeof(Host) );
		host.hostSub = *hostSub;
		MakeListString( cfg, &host, buf );
	}
}

void MakeListString( Cfg* cfg, Host* host, char* buf )
{
	char* fmt = "%s";
	if( *host->nickName )
	{
		if( cfg->nickNameCheck == IPMSG_NICKNAME )
			buf += wsprintf( buf, fmt, host->nickName );
		else
		{
			char tmpName[MAX_LISTBUF] = {0};
			wsprintf( tmpName, "%s[%s]", host->nickName, host->hostSub.userName );
			buf += wsprintf( buf, fmt, tmpName );
		}
	}
	else buf += wsprintf( buf, fmt, host->hostSub.userName );
	
	if( host->hostStatus & IPMSG_ABSENCEOPT )
		*buf++ = '*';
	buf += wsprintf( buf, "(%s%s%s", host->groupName, *host->groupName ? "/" : "", host->hostSub.hostName );
	if( cfg->ipAddrCheck )
		buf += wsprintf( buf, "/%s", inet_ntoa(*(LPIN_ADDR)&host->hostSub.addr) );
	strcpy( buf, ")" );
}